<template>
  <div class="hello">
      <h1 style="text-align:center;">登陆成功，正在跳转中....</h1>
  </div>
</template>

<script>
import applicationUserManager from '@/auth/applicationusermanager';
import {LoginOrRegister} from '@/api/accessmanage'
export default {
  name: 'callback',
  data () {
    return {
        bindDialog:false,

        sendCodeText:'发送验证码',
        sendDisabled:false,
        sendCodeBtnLoading:false,
        verificatLoading:false,
        verificationPhone:null,
        verificationCode:null,
        timer:null,
        tokenTime:null
    }
  },
  created(){
   
  },
   async mounted() {
      let _that = this;
        await applicationUserManager.signinRedirectCallback()
        const user = await applicationUserManager.getUser();
        if (user) {
          this.tokenTime = new Date(user.expires_at*1000)
          this.$cookie.set('ACCESS_TOKEN',user.access_token,{expires:this.tokenTime});
          this.$cookie.set('TOEKN_TYPE',user.token_type,{expires:this.tokenTime});
          this.$cookie.set('ID_TOKEN',user.id_token,{expires:this.tokenTime});
          this.isEmployeeFn();
        }else{
          alert('获取用户信息失败')
        }
  },
  methods:{
      async isEmployeeFn(){
        try {
            let res = await LoginOrRegister();
            console.log(res);
            if(res.code === 200){
              // if(!res.data.isSalesman){
              //   this.$cookie.remove('ACCESS_TYPE');
              //   this.$cookie.remove('ACCESS_TOKEN');
              //   this.$cookie.remove('ID_TOKEN');
              //   window.localStorage.clear();
              //   this.$alert('您没有权限访问管理平台', '提示', {
              //       confirmButtonText: '确定',
              //       center:true,
              //       callback: action => {
              //         applicationUserManager.logout();
              //       }
              //     });
              // }else{
                this.$cookie.set('USER_ID',res.data.id,{expires:this.tokenTime});
                this.$cookie.set('SET_NAME',res.data.nickname,{expires:this.tokenTime});
                this.$cookie.set('SET_HERDER_IMAGE',res.data.headImg,{expires:this.tokenTime});
                this.$store.commit('user/SET_NAME',res.data.nickname)
                this.$store.commit('user/SET_HERDER_IMAGE',res.data.headImg)
                this.$router.push({
                    path: '/'
                })
              // }
            }else if(res.code === 1001){
                this.bindDialog = true;
                this.$router.push({
                  path: '/'
              })
            }else if(res.code === 401){
                 this.$router.push({
                    path: '/401'
                })
            } else{
              this.$router.push({
                  path: '/'
              })
            }
            
            
         } catch (error) {
             
         }
      },
      timeGo(){
          clearInterval(this.timer);
          let that = this;
          let timeNum = 5;
          this.sendDisabled = true;
          this.timer = setInterval(function(){
              
              that.sendCodeText = timeNum +'s 后重新发送';
              if(timeNum<=0){
                  clearInterval(that.timer);
                  that.sendCodeText = '点击发送验证码'
                  that.sendDisabled = false;
              }
              timeNum -- ;

          },1000)
      }
  }
}
</script>

<style lang="scss">
.bind-dialog{
     .el-dialog__header{
         font-weight: bold;
         text-align: center;
     }
 }
</style>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import '~@/styles/mixin.scss';
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
 .verification-box{
     @include _display(flex);
     @include _justify(space-between);
     margin: 20px 0;
     
 }
 
</style>

